package com.hemaapp.yjnh.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.uu.utils.uuUtils;
import com.hemaapp.hm_FrameWork.HemaAdapter;
import com.hemaapp.yjnh.R;
import com.hemaapp.yjnh.bean.Pay;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 充值记录
 */
public class PayAdapter extends HemaAdapter {

    private ArrayList<Pay> pays;

    public PayAdapter(Context mContext, ArrayList<Pay> pays) {
        super(mContext);
        this.pays = pays;
    }

    @Override
    public int getCount() {
        int size = pays == null ? 0 : pays.size();
        return size == 0 ? 1 : pays.size();
    }

    @Override
    public boolean isEmpty() {
        int size = pays == null ? 0 : pays.size();
        return size == 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (isEmpty())
            return getEmptyView(parent);
        ViewHolder holder;
        if (convertView == null || convertView.getTag(R.id.TAG_VIEWHOLDER) == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_cash_record, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(R.id.TAG_VIEWHOLDER, holder);
        } else {
            holder = (ViewHolder) convertView.getTag(R.id.TAG_VIEWHOLDER);
        }
        holder.setDatas(position);
        return convertView;
    }

    class ViewHolder {
        @Bind(R.id.iv_way)
        ImageView ivWay;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_date)
        TextView tvDate;
        @Bind(R.id.tv_total_fee)
        TextView tvTotalFee;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }

        public void setDatas(int position) {
            Pay pay = pays.get(position);
            String payType = pay.getPaytype();
            if ("1".equals(payType)) {// 支付宝
                ivWay.setImageResource(R.drawable.img_paytyp_alipay);
                tvName.setText("支付宝充值");
            } else if ("2".equals(payType)) {// 银联
                ivWay.setImageResource(R.drawable.img_paytyp_union);
                tvName.setText("银联充值");
            } else if ("3".equals(payType)) {//微信
                ivWay.setImageResource(R.drawable.img_paytyp_wechat);
                tvName.setText("微信充值");
            }
            tvDate.setText(pay.getRegdate());
            tvTotalFee.setText("+"+uuUtils.formatAfterDot2(pay.getTotal_fee()));
        }
    }
}
